/**
 * 功能:TK_WAREHOUSE_ACCOUNTS Service类
 * 开发人员:chengd
 * 创建时间:2012/4/23 19:33:09
 */
package com.towker.frame.service.warehouse;

import org.springframework.stereotype.Service;
import com.towker.core.db.EntityDao;
import com.towker.core.db.BaseService;
import com.towker.frame.model.basicData.Depots;
import com.towker.frame.model.basicData.SurplusOrder;
import com.towker.frame.model.warehouse.WarehouseAccounts;
import com.towker.frame.service.basicData.DepotsService;
import com.towker.frame.dao.warehouse.WarehouseAccountsDao;

@Service
public class WarehouseAccountsService extends BaseService<WarehouseAccounts, java.lang.Long>
{
	private WarehouseAccountsDao dao;
	
	public void setWarehouseAccountsDao(WarehouseAccountsDao dao)
	{
		this.dao = dao;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	protected EntityDao getEntityDao()
	{
		return this.dao;
	}
	
	public void addStockAmount(String goodsSn, String depotCode, String coCode, double amount) {
		WarehouseAccounts wa = this.dao.getByDepotAndGoods( goodsSn, depotCode, coCode);
		if (wa == null) {
			wa = new WarehouseAccounts();
			wa.setGoods_sn(goodsSn);
			wa.setDep_code(depotCode);
			wa.setStock_num(amount);
			wa.setCo_code(coCode);
			add(wa);
		} else {
			wa.setStock_num(wa.getStock_num()+amount);
			update(wa);
		}
	}
}
